package com.task.manager.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import com.task.manager.domain.Task;
import com.task.manager.domain.TaskResult;

public interface TaskResultMapper {
	@Delete({ "delete from t_task_result", "where ID = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into t_task_result (ID, TASK_CODE, ", "TASK_NAME, TASK_PARAM, ", "TASK_URL, TASK_HEADER, ", "ACTUATOR_CODE, ACTUATOR_TYPE, ", "RETRY_NUM, BATCH_NO, ", "IP_ADDRESS, INPUT, ",
			"OUTPUT, RESULT, EXCEPTION, ", "NEXT_TIME, EXECUTE_TIME, ", "REMARK)", "values (#{id,jdbcType=INTEGER}, #{taskCode,jdbcType=VARCHAR}, ",
			"#{taskName,jdbcType=VARCHAR}, #{taskParam,jdbcType=VARCHAR}, ", "#{taskUrl,jdbcType=VARCHAR}, #{taskHeader,jdbcType=VARCHAR}, ",
			"#{actuatorCode,jdbcType=VARCHAR}, #{actuatorType,jdbcType=VARCHAR}, ", "#{retryNum,jdbcType=INTEGER}, #{batchNo,jdbcType=VARCHAR}, ",
			"#{ipAddress,jdbcType=VARCHAR}, #{input,jdbcType=VARCHAR}, ", "#{output,jdbcType=VARCHAR}, #{result,jdbcType=BIT}, #{exception,jdbcType=VARCHAR}, ",
			"#{nextTime,jdbcType=TIMESTAMP}, #{executeTime,jdbcType=TIMESTAMP}, ", "#{remark,jdbcType=LONGVARCHAR})" })
	int insert(TaskResult record);

	@InsertProvider(type = TaskResultSqlProvider.class, method = "insertSelective")
	int insertSelective(TaskResult record);

	@Select({ "select", "ID, TASK_CODE, TASK_NAME, TASK_PARAM, TASK_URL, TASK_HEADER, ACTUATOR_CODE, ", "ACTUATOR_TYPE, RETRY_NUM, BATCH_NO, IP_ADDRESS, INPUT, OUTPUT, RESULT, EXCEPTION, ",
			"NEXT_TIME, EXECUTE_TIME, REMARK", "from t_task_result", "where ID = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "ID", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "TASK_CODE", property = "taskCode", jdbcType = JdbcType.VARCHAR),
			@Result(column = "TASK_NAME", property = "taskName", jdbcType = JdbcType.VARCHAR), @Result(column = "TASK_PARAM", property = "taskParam", jdbcType = JdbcType.VARCHAR),
			@Result(column = "TASK_URL", property = "taskUrl", jdbcType = JdbcType.VARCHAR), @Result(column = "TASK_HEADER", property = "taskHeader", jdbcType = JdbcType.VARCHAR),
			@Result(column = "ACTUATOR_CODE", property = "actuatorCode", jdbcType = JdbcType.VARCHAR), @Result(column = "ACTUATOR_TYPE", property = "actuatorType", jdbcType = JdbcType.VARCHAR),
			@Result(column = "RETRY_NUM", property = "retryNum", jdbcType = JdbcType.INTEGER), @Result(column = "BATCH_NO", property = "batchNo", jdbcType = JdbcType.VARCHAR),
			@Result(column = "IP_ADDRESS", property = "ipAddress", jdbcType = JdbcType.VARCHAR), @Result(column = "INPUT", property = "input", jdbcType = JdbcType.VARCHAR),
			@Result(column = "OUTPUT", property = "output", jdbcType = JdbcType.VARCHAR), @Result(column = "RESULT", property = "result", jdbcType = JdbcType.BIT),
			@Result(column = "EXCEPTION", property = "exception", jdbcType = JdbcType.VARCHAR), @Result(column = "NEXT_TIME", property = "nextTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "EXECUTE_TIME", property = "executeTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "REMARK", property = "remark", jdbcType = JdbcType.LONGVARCHAR) })
	TaskResult selectByPrimaryKey(Integer id);

	@UpdateProvider(type = TaskResultSqlProvider.class, method = "updateByPrimaryKeySelective")
	int updateByPrimaryKeySelective(TaskResult record);

	@Update({ "update t_task_result", "set TASK_CODE = #{taskCode,jdbcType=VARCHAR},", "TASK_NAME = #{taskName,jdbcType=VARCHAR},", "TASK_PARAM = #{taskParam,jdbcType=VARCHAR},",
			"TASK_URL = #{taskUrl,jdbcType=VARCHAR},", "TASK_HEADER = #{taskHeader,jdbcType=VARCHAR},", "ACTUATOR_CODE = #{actuatorCode,jdbcType=VARCHAR},",
			"ACTUATOR_TYPE = #{actuatorType,jdbcType=VARCHAR},", "RETRY_NUM = #{retryNum,jdbcType=INTEGER},", "BATCH_NO = #{batchNo,jdbcType=VARCHAR},", "IP_ADDRESS = #{ipAddress,jdbcType=VARCHAR},",
			"INPUT = #{input,jdbcType=VARCHAR},", "OUTPUT = #{output,jdbcType=VARCHAR},", "RESULT = #{result,jdbcType=BIT},", "EXCEPTION = #{exception,jdbcType=VARCHAR},",
			"NEXT_TIME = #{nextTime,jdbcType=TIMESTAMP},", "EXECUTE_TIME = #{executeTime,jdbcType=TIMESTAMP},", "REMARK = #{remark,jdbcType=LONGVARCHAR}", "where ID = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKeyWithBLOBs(TaskResult record);

	@Update({ "update t_task_result", "set TASK_CODE = #{taskCode,jdbcType=VARCHAR},", "TASK_NAME = #{taskName,jdbcType=VARCHAR},", "TASK_PARAM = #{taskParam,jdbcType=VARCHAR},",
			"TASK_URL = #{taskUrl,jdbcType=VARCHAR},", "TASK_HEADER = #{taskHeader,jdbcType=VARCHAR},", "ACTUATOR_CODE = #{actuatorCode,jdbcType=VARCHAR},",
			"ACTUATOR_TYPE = #{actuatorType,jdbcType=VARCHAR},", "RETRY_NUM = #{retryNum,jdbcType=INTEGER},", "BATCH_NO = #{batchNo,jdbcType=VARCHAR},", "IP_ADDRESS = #{ipAddress,jdbcType=VARCHAR},",
			"INPUT = #{input,jdbcType=VARCHAR},", "OUTPUT = #{output,jdbcType=VARCHAR},", "RESULT = #{result,jdbcType=BIT},", "EXCEPTION = #{exception,jdbcType=VARCHAR},",
			"NEXT_TIME = #{nextTime,jdbcType=TIMESTAMP},", "EXECUTE_TIME = #{executeTime,jdbcType=TIMESTAMP}", "where ID = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKey(TaskResult record);
	
	@Select({"select * from t_task_result","where BATCH_NO = #{batchNo,jdbcType=VARCHAR}"})
	List<TaskResult> queryByBatchNo(String batchNo);
	
	@Select({ " select ", " * ", " from t_task_result ","order by id desc" })
	List<TaskResult> queryAll();
	
	@SelectProvider(type = TaskResultSqlProvider.class, method = "queryTaskResultByParam")
	List<TaskResult> queryTaskResultByParam(TaskResult record);
	
}